package com.errorfinding.rabbitmq.eight;

import com.errorfinding.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 * 交换机模式 直接模式 direct
 * 死信队列
 */
public class Producer {

    //普通交换机名称
    private static final String normal_exchange="normal_exchange";

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取信道
        Channel channel = RabbitMqUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(normal_exchange,"direct");
        //发送死信消息 设置TTL(存活时间)时间 单位 毫秒 测试 1.过期时间进入死信队列
        //AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();
        for (int i = 1; i < 11; i++) {
            String message = "info"+i;
            //channel.basicPublish(normal_exchange,"zhangsan",properties,message.getBytes());  测试 1.过期时间进入死信队列
            channel.basicPublish(normal_exchange,"zhangsan",null,message.getBytes());
        }
    }

}
